package FenxiaoService

import (
	"context"
	"gdshop-font-api-go/app/request/FenxiaoReq"
	"gdshop-font-api-go/app/service/GoodsBaseService"
	"gdshop-font-api-go/library/response"
	"github.com/gogf/gf/frame/g"
)

func GoodsFollowList(ctx context.Context, parames *FenxiaoReq.GoodsFollowList) *response.JsonResponse {
	fuModel, err := GetFenxiaoUserModelByMemberId(ctx, int(parames.MemberId))
	if err != nil {
		return response.FailByRequestMessage(nil, err.Error())
	}
	dbPrefix := g.Cfg().GetString("database.prefix")
	where := g.Map{
		"g.delete_at < ?": 1,
		"g.id IN (SELECT goods_id FROM " + dbPrefix + "fenxiao_goods_follow WHERE delete_at<1 AND fenxiao_user_id = ?)": fuModel.Id,
	}

	jieguo, err := GoodsBaseService.GetPager(ctx, where, parames.Page, parames.PageSize, "")
	if err != nil {
		return response.FailByRequestMessage(nil, err.Error())
	}
	memberId := int(parames.MemberId)
	// 处理分销信息
	jieguo, err = handleFenxiaoInfo(ctx, memberId, jieguo)
	if err != nil {
		return response.FailByRequestMessage(nil, err.Error())
	}

	return response.SuccessByRequestMessageData(nil, "成功", jieguo)
}
